<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.inventoryFlow.HeadqInventoryFlowOrder"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>千禧宝贝连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/inventory/inventory.js?v=1.17"></script>
    <style>
        #chat-box{
            height: 560px; width: 96%; margin-bottom: 5px; overflow:auto; border: 1px solid #999;
        }
    </style>
<script>
var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	loadResult();
	var orderId = $("#orderId").val();
	$('#dataGrid').edatagrid({
			url : 'headqInventoryFlowJSONAction!selectOrderProducts',
			queryParams: {
				'formBean.flowOrder.id':orderId
			},
            fitColumns: true,
            fit: true,
            singleSelect: true,
            rowStyler: function(index,row){
    			var style = "";
    			if (row.quantity > 3)
    				style += 'color:red;';
    			return style;
    		},
    		editable: false,
            columns: [[
                {field: 'id', title: '编号', width: 30},
                {field: 'pbId', title: '条码ID', width: 80, hidden:true},
                {field: 'barcode', title: '条码', width: 80, editor: false},
                {field: 'productCode', title: '货号', width: 70, editor: false},
                {field: 'colorName', title: '颜色', width: 60, editor: false},
                {field: 'brand', title: '品牌', width: 80, editor: false},
                {field: 'categoryLevel', title: '产品线', width: 50, editor: false},
                {field: 'category', title: '货品类别', width: 60, editor: false},
                {field: 'year', title: '年份', width: 40, editor: false,
                	formatter : function(value, row, index) {	
                		return row.year + row.quarter;
                	}
                },
                {field: 'unit', title: '单位', width: 30, editor: false},
                {field: 'salesPrice', title: '批发单价', width: 40, editor: false},
                {field: 'quantity', title: '纠正数量', width: 40, editor: false},
                {field: 'totalWholePrice', title: '批发总价', width: 50, editor: false},
                {field: 'inventoryQ', title: '电脑库存', width: 40, editor: false},
                {field: 'action1', title: '纠正后数量', width: 30, editor: false,
                	formatter : function(value, row, index) {

                		if ($("#orderType").val() == 1)
                		   return row.quantity - (row.inventoryQ * -1);
                		else 
                		  return row.inventoryQ - row.quantity;
                	}},
                {field: 'action', title: '图片', width: 30,
        			formatter : function(value, row, index) {
        				var str = '';     				
        				str += $.formatString('<a href="#" onclick="viewImgP(\'{0}\');"><img border="0" src="{1}" /></a>', row.barcode,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/img3.png');        			       				
        				return str;
        			}},
        		{field: 'scanNums', title: '扫描次数', width: 30, editor: false},
        		{field: 'comment', title: '备注', width: 40, editor: 'text'}
            ]]});
	
	//计算合计
	 var totalQuantity = $("#totalQuantity").val();
	 var totalInventoryQ = $("#totalInventoryQ").val();
	 var totalQuantityDiff = $("#totalQuantityDiff").val();
	 $("#sumQuantity").val(totalQuantity);
	 $("#inventoryQuantity").val(totalInventoryQ);
	 $("#correctQuantity").val(totalQuantityDiff);
});

/**
 * 单据校验
 */
function validateInvenFlowForm(){
	var totalQ = $("#sumQuantity").val();
	var file = $("#inventory").textbox('getValue');
	if (totalQ == 0 && file == ""){
		$.messager.alert('错误', '请输入货品或者导入盘点文件后再操作单据', 'warning');
		return false;
	}
    return true;
						
}

/**
 * 保存草稿
 */
function saveToDraft(){
	if(validateInvenFlowForm()){
		saveBeforeLoad();		
		document.headqInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!saveToDraft";
		document.headqInventoryFlowForm.submit();
		$.messager.progress({
    	    title:'请稍候',
    	    msg:'数据加载中...'
    	});
	}
}

/**
 * 保存单据
 */
function saveOrder() {
	if(validateInvenFlowForm()){
		saveBeforeLoad();
		document.headqInventoryFlowForm.action = "action/headqInventoryFlowJSPAction!saveToFinal";
		document.headqInventoryFlowForm.submit();
	}
}
/**
 *保存单据：回调
 */
function saveOrderBackProcess(date){
	var returnCode = date.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', date.message, 'error');
	else {
		$.messager.alert('保存草稿提示', date.message, 'info');
	}
}	


</script>
</head>
<body>
<s:form action="/action/inventoryFlowAction!saveToDraftN" method="POST" name="headqInventoryFlowForm" enctype="multipart/form-data" id="headqInventoryFlowForm" theme="simple">
	<s:hidden id="orderType" name="formBean.flowOrder.type"/>  
	<s:hidden id="orderId" name="formBean.flowOrder.id"/>   
	<s:hidden name="formBean.flowOrder.status"/> 
	<input type= "hidden" id="totalQuantity"  value='<s:property value="formBean.flowOrder.totalQuantity"/>'></input>
	<input type= "hidden" id="totalInventoryQ"  value='<s:property value="formBean.flowOrder.totalInventoryQ"/>'></input>
	<input type= "hidden" id="totalQuantityDiff"  value='<s:property value="formBean.flowOrder.totalQuantityDiff"/>'></input>
	<input type= "hidden" id="jsons"  name="formBean.jsons"></input>
	<input type="hidden" id="result" name="formBean.responseMsg"></input>
	    <table width="95%" align="center"  class="OuterTable">
	    <tr><td>
	      <div class="errorAndmes">
	      <!-- 	 注释：旧JSP响应后台返回信息     <s:actionerror cssStyle="color:red"/><s:actionmessage cssStyle="color:blue"/> -->

	      <%@ include file="../common/JRComponent.jsp"%>
	      </div>
			 <table width="100%" border="0">
			    <tr>
			       <td height="50" colspan="7">
				   	 <table width="100%" border="0">
				       <tr class="PBAOuterTableTitale">
				         <td height="35" colspan="5">
				         <s:if test="formBean.flowOrder.type == 1">
				        	<span style="color:green"><s:property value="formBean.flowOrder.typeHQS"/>：<s:property value="formBean.flowOrder.statusInfo"/></span>
				         </s:if>
				         <s:if test="formBean.flowOrder.type == 2">
				         	<span style="color:red"><s:property value="formBean.flowOrder.typeHQS"/>：<s:property value="formBean.flowOrder.statusInfo"/></span>
				         </s:if>
				         
				         <span style="position:relative;left:85%;">单据号：
				         		<s:if test="formBean.flowOrder.id != 0">
				        		   	<s:property value="formBean.flowOrder.id"/>
				        		  </s:if>
				         	</span>	
				         </td>				         
			           	 
			           </tr>
				       <tr class="InnerTableContent">
				       	<td width="18%" height="40"><%@ include
												file="../common/SearchProductCodeInput.jsp"%></strong></td>
				         <td width="10%"><strong>创建人:</strong>&nbsp &nbsp<s:property value="formBean.flowOrder.creator.name"/></td>
				         <td width="20%"><strong>单据日期:</strong>&nbsp &nbsp<s:property value="formBean.flowOrder.orderDate"/></td>
				        				        
				         <td  width="17%"><strong>仓库信息：</strong>
				         		<s:select name="formBean.flowOrder.storeId"  cssClass="easyui-combobox" style="width:140px"  size="1" id="storeId" list="uiBean.stores" listKey="id" listValue="name"  data-options="editable:false"/>
				         </td>
				         <td><strong>数量：</strong>
				         	<input class="easyui-textbox" id="correctNums" data-options="prompt:'请输入纠正数量',searcher:insert" style="width:130px">
				         <a href="javascript:void(0)" class="easyui-linkbutton c6" onclick="updateRow()" style="width:80px; height: 25px;">修改行</a><a href="javascript:void(0)" class="easyui-linkbutton c7" onclick="deleteRow()" style="width:80px;height: 25px;">删除行</a></td>
				       </tr>

				     </table></td>
			    </tr>			    			    
			    <tr>
			      <td colspan="7">
			            <!-- table to display the product information -->
								<div id="chat-box">
									<table id="dataGrid" style="width: 1700px;">
									</table>
								</div>
							</td>
			    </tr>
			    <tr class="InnerTableContent">
			      <td colspan="7">
			            
						<table width="100%" align="left" border="0">
						<tr class="InnerTableContent">
															
								<td></td>
								<td></td>
								<td></td>
								<td><strong>盘点总数量：</strong><input type="button" id="sumQuantity"  style="height:25px;width:75px;color:red;text-align:center;border-radius:10%; font-size: 12px;"  disabled="disabled"/>
									<strong>库存总数量：</strong><input type="button" id="inventoryQuantity"  style="height:25px;width:75px;color:red;text-align:center;border-radius:10%; font-size: 12px;"  disabled="disabled"/>
									<strong>纠正：</strong><input type="button" id="correctQuantity"  style="height:25px;width:75px;color:red;text-align:center;border-radius:10%; font-size: 12px;"  disabled="disabled"/>
								</td>
							</tr>
						<tr class="InnerTableContent">
																
								<td width="5%" align="left" height="40"><strong>文件上传:</strong></td>
								<td width="15%"><input class="easyui-filebox" id="inventory"  name="formBean.inventory" data-options="prompt:'请上传新增条码文件',buttonText: '条码文件',buttonAlign: 'left'" style="width:90%"></input>
								<td width="5%" align="right"><strong>备注:</strong></td>
								<td width="50%"><s:textfield cssClass="easyui-textbox" data-options="prompt:'请输入单据备注信息！'" style="width:50%"
												name="formBean.flowOrder.comment" size="50" /></td>						
							</tr>
						  			 
						  <tr class="InnerTableContent">
						    <td  align='left'><strong>选择操作:</strong></td>

						    <td colspan="3" align='left'>
						    	<s:if test="#session.LOGIN_USER.containFunction('headqInventoryFlowJSPAction!saveToDraft')">					
									<a href="javascript:void(0)" class="easyui-linkbutton c4" onclick="saveToDraft()" style="width:100px">存入草稿</a>
								</s:if>
								<s:if test="#session.LOGIN_USER.containFunction('headqInventoryFlowJSPAction!saveToFinal')">
									<a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="saveOrder()" style="width:100px">单据过账</a>		
								</s:if>																																			 				      					
						    </td>
					      </tr>
					    </table>
				  </td>
			    </tr>
			    <tr class="InnerTableContent">
			      <td height="4" colspan="7"><hr width="100%" color="#FFCC00"/></td>
			    </tr>
			  </table>
	   </td></tr>
	 </table>
	  
	 </s:form>
	
</body>
</html>

